<script language="javascript">
	function hoanthanh()
	{
		opener.document.getElementById('dskh').innerHTML=document.getElementById('themdskh').innerHTML;
		close();
	}
</script>
</head>

<body>
<?php
	$ht=$_POST['hoten'];
	$cmnd=$_POST['cmnd'];
	$diachi=$_POST['diachi'];
	$dienthoai=$_POST['dienthoai'];
	$mail=$_POST['mail'];
	include('../csdl.php');
	$knoi=new csdl();
	$k=$knoi->queryCsdl('select max(makh) as max_makh from khachhang');
	$l=mysql_fetch_array($k);
	$max_makh=$l['max_makh'];
	if($max_makh=='')
		$makh='0000001';
	else
	{
		$makh=1 + $max_makh;
		$sl= 7 - count($makh);
		//echo $sl."<br>";
		for($i=0;$i<$sl;$i++)
		{
			$makh='0'.$makh;
		}
	}
	if($kq=$knoi->queryCsdl("insert into khachhang values('$makh','$ht','$cmnd','$diachi','$dienthoai','$mail')"))
	{
		$m=$knoi->queryCsdl("select makh,tenkh from khachhang where makh!='$makh'");
	?>
		<div id="themdskh" style="position:relative; float:left;">
			<select name="khachhang">
				<option value="<?php echo $makh; ?>"><?php echo $ht; ?></option>
	<?php
				while($n=mysql_fetch_array($m))
				{
	?>
					<option value="<?php echo $n['makh']; ?>"><?php echo $n['tenkh']; ?></option>
	<?php
				}
	?>
			</select>
		</div>
		<script language="javascript">
			hoanthanh();
		</script>
	<?php
	}
	else
	{
	?>
		<script language="javascript">
			alert("Có lỗi xãy ra. Xin vui lòng kiểm tra lại!");
			close();
		</script>
	<?php
	}
?>
